﻿using System.Collections;
using System.Data;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media; 
using SLS.DataBase;
using SLS.DataBase.SLDBSETTableAdapters; 
using System;
using System.Reflection;
namespace LanSunStudio.GUI
{ 
public partial class HomeDocument:Window
    {
        SLDBSET Set2Load;    
        DataSet Set2Save;
        string AppXMLPath = ""; 
        public string ExControlXMLPath
        {
            get
            {
                AppXMLPath = System.IO.Directory.GetCurrentDirectory().ToString().Trim();
                AppXMLPath = AppXMLPath + @"\ExXML";
                if (!System.IO.Directory.Exists(AppXMLPath))
                    System.IO.Directory.CreateDirectory(AppXMLPath);
                AppXMLPath = AppXMLPath + @"\Set2Load.xml";
                return AppXMLPath;
            } 
        }
        public HomeDocument()
        {
   
            InitializeComponent();          
         
        } 
  
        private void LoadData()
        {
            try
            {
                #region Load all the table data
                MessageExtendTableAdapter tempt1 = new MessageExtendTableAdapter();
                tempt1.Fill(Set2Load.MessageExtend);
                Set2Save.Merge(Set2Load.AgentList);
                AgentListTableAdapter tempta = new AgentListTableAdapter();
                tempta.Fill(Set2Load.AgentList);
                Set2Save.Merge(Set2Load.AgentList);
                FOREIGNKEYLISTTableAdapter temptb = new FOREIGNKEYLISTTableAdapter();
                temptb.Fill(Set2Load.FOREIGNKEYLIST);
                Set2Save.Merge(Set2Load.FOREIGNKEYLIST);
                TABLELISTTableAdapter temptc = new TABLELISTTableAdapter();
                temptc.Fill(Set2Load.TABLELIST);
                Set2Save.Merge(Set2Load.TABLELIST);
                GTDEFTableAdapter temptd = new GTDEFTableAdapter();
                temptd.Fill(Set2Load.GTDEF);
                Set2Save.Merge(Set2Load.GTDEF);
                GTKRTableAdapter tempte = new GTKRTableAdapter();
                tempte.Fill(Set2Load.GTKR);
                Set2Save.Merge(Set2Load.GTKR);
                GTARTableAdapter temptf = new GTARTableAdapter();
                temptf.Fill(Set2Load.GTAR);
                Set2Save.Merge(Set2Load.GTAR);
                GTPRTableAdapter temptg = new GTPRTableAdapter();
                temptg.Fill(Set2Load.GTPR);
                Set2Save.Merge(Set2Load.GTPR);
                GOODSTYPETableAdapter tempth = new GOODSTYPETableAdapter();
                tempth.Fill(Set2Load.GOODSTYPE);
                Set2Save.Merge(Set2Load.GOODSTYPE);
                MenuBuildTableAdapter tempti = new MenuBuildTableAdapter();
                tempti.Fill(Set2Load.MenuBuild);
                Set2Save.Merge(Set2Load.MenuBuild);
                this.DataContext = Set2Save;
                #endregion

                if (File.Exists(ExControlXMLPath))
                {
                    File.Delete(ExControlXMLPath);
                }
                else
                {
                    // File.Create(ExControlXMLPath);
                }
                string outputfile = "";
                outputfile = @"D:\SkyDrive\LanSunStudio\Exe\ExXML\Set4BL.xml";
                Set2Load.WriteXml(outputfile);
                outputfile = @"D:\SkyDrive\LanSunStudio\SVC\ExXML\Set4BL.xml";
                Set2Load.WriteXml(outputfile);
                outputfile = @"D:\SkyDrive\LanSunStudio\Exe\ExXML\Set4UI.xml";
                Set2Load.WriteXml(outputfile);
                outputfile = @"D:\SkyDrive\LanSunStudio\SVC\ExXML\Set4UI.xml";
                Set2Load.WriteXml(outputfile);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void btnLoadData_Click_1(object sender, RoutedEventArgs e)
        {
            Set2Load = new SLDBSET();
            Set2Save = new DataSet();
            LoadData();
        }
    }
}
